package com.ctcs.controller;

import com.ctcs.domain.Movie;
import com.ctcs.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by duyaming on 2017/8/29.
 */
@Controller
public class MovieController {
    @Autowired
    private MovieService movieService;

    @RequestMapping("/")
    public String movieList(Integer page,ModelMap map){
        if ("".equals(page)||page==null){
            page=0;
        }
       // System.out.println(page);
        List<Movie> movieList =movieService.movieList(page);
        map.addAttribute("movieList",movieList);
        map.addAttribute("page",page+1);
        return "index";
    }
    @RequestMapping("findById/{id}")
    public String findById(@PathVariable("id") Integer id, ModelMap map){
        Movie movie=movieService.findById(id);
        map.addAttribute("movie",movie);
        return "info";
    }




}
